
package ch.hearc.coursJava.moo;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class PileTest
	{

	/*------------------------------------------------------------------*\
	 |*							Constructeurs							*|
	 \*------------------------------------------------------------------*/

	@Before
	public void before()
		{
		// rien
		}

	@After
	public void after()
		{
		// rien
		}

	/*------------------------------------------------------------------*\
	 |*							Methodes Public							*|
	 \*-----------------------------------------------------------------*/

	@Test
	public void testPileInteger()
		{
		Pile<Integer> pile = new Pile<Integer>();
		assertTrue(pile.size() == 0);
		assertTrue(pile.isEmpty());
		pile.push(1);
		assertTrue(pile.size() == 1);
		assertFalse(pile.isEmpty());
		pile.push(2);
		pile.push(3);
		System.out.println(pile);
		assertTrue(pile.pop() == 3);
		assertTrue(pile.pop() == 2);
		assertTrue(pile.size() == 1);
		}

	@Test
	public void testPileString()
		{
		Pile<String> pile = new Pile<String>();
		assertTrue(pile.size() == 0);
		assertTrue(pile.isEmpty());
		pile.push("a");
		System.out.println(pile);
		assertTrue(pile.size() == 1);
		assertFalse(pile.isEmpty());
		pile.push("b");
		System.out.println(pile);
		pile.push("c");
		System.out.println(pile);
		assertTrue(pile.pop() == "c");
		System.out.println(pile);
		assertTrue(pile.pop() == "b");
		System.out.println(pile);
		assertTrue(pile.size() == 1);
		}

	@Test
	public void testPopSafe1()
		{
		Pile<String> pile = new Pile<String>();
		pile.push("a");
		pile.pop();
		try
			{
			pile.popSafe();
			Assert.fail();
			}
		catch (Exception e)
			{
			// tout est ok!!
			}
		}

	@Test
	public void testPopSafe2()
		{
		Pile<String> pile = new Pile<String>();
		pile.push("a");
		try
			{
			pile.popSafe();
			}
		catch (Exception e)
			{
			Assert.fail();
			}
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	}
